#include "comm.hpp"

int main()
{
    key_t k = getKey();
    printf("key: 0x%x\n", k);
    int shmid = createShm(k);
    printf("shmid: %d\n", shmid);

    // sleep(5);
    char *start = (char *)attachShm(shmid);
    printf("attch success,address start:%p\n", start);

    // sleep(5);

    // 通信
    while (true)
    {
        printf("client say : %s\n", start);
        struct shmid_ds ds;
        shmctl(shmid, IPC_STAT, &ds);
        printf("获取属性：size:%d,pid:%d,myself:%d,key:0x%x ", ds.shm_segsz, ds.shm_cpid, getpid(), ds.shm_perm.__key);
        sleep(1);
    }
    // 管道读取方式：
    // char buffer[]; read(pipefd, buffer, ...)

    // 去关联
    detachShm(start);

    // sleep(5);
    delShm(shmid);

    return 0;
}
